package com.latefly.skewwork.ui.page.practice

import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import com.latefly.skewwork.R

@Composable
fun MessageList(messages: List<MessageData>) {
    LazyColumn {

        items(messages) { message ->
            Message(message = message)
            Spacer(modifier = Modifier.height(10.dp))
        }
    }
}

@Composable
fun Message(message: MessageData, modifier: Modifier = Modifier) {

    Row {
        Image(
            painter = painterResource(
                id = R.drawable.ic_launcher_background
            ),
            contentDescription = null,
            modifier = Modifier
                .clip(CircleShape)
                .size(40.dp)
        )
        Spacer(modifier = Modifier.width(20.dp))

        var isExpanded by remember {
            mutableStateOf(false)
        }
        Column(modifier = Modifier.clickable {
            isExpanded = !isExpanded;
        }) {
            Text(
                text = message.author,
                modifier = Modifier
                    .size(20.dp),
            )
            Text(
                text = message.tips,
                color = MaterialTheme.colorScheme.secondaryContainer,
                maxLines = if (isExpanded) 10000 else 1
            )
        }

    }
}

fun getMessages():List<MessageData>{
    return listOf<MessageData>(
        MessageData("aa", "1111"),
        MessageData(
            "cc",
            "221111111111111111111111111111111111111111111111111111111111111111"
        ),
        MessageData("dd", "3333"),
        MessageData(
            "cc",
            "221111111111111111111111111111111111111111111111111111111111111111"
        ),

        )
}

data class MessageData(val author: String, val tips: String)
